﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Carbon.Web.Forms.jQueryForms;

namespace Demo
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        
        private Example m_ExampleContext = default(Example);
        private bool m_ExampleContext_calculated = false;
        public Example ExampleContext
        {
            get
            {
                if (!m_ExampleContext_calculated)
                {
                    String url = this.Request.Url.GetComponents(UriComponents.PathAndQuery, UriFormat.Unescaped);
                    int index = 0;

                    index = url.IndexOf('?');

                    if (index > 0)
                    {
                        url = url.Substring(0, index);
                    }

                    foreach (Example example in Examples.AllExamples) 
                    {
                        if (string.Compare(url, example.Url, true) == 0)
                        {
                            m_ExampleContext = example;
                        }
                    }

                     if (m_ExampleContext == null)  throw new NullReferenceException("m_ExampleContext");
                    m_ExampleContext_calculated = true;
                }

                return m_ExampleContext;
            }
        }

   

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.Page.ClientTarget = Constants.ClientAllPossibilities;

            try
            {
                this.Page.Title = ExampleContext.Title;
            }
            catch
            {
            }
        }
    }
}
